package com.wolf.etl.core.rule.check;

import com.wolf.vo.BaseResult;
import org.springframework.stereotype.Component;

import java.util.regex.Pattern;

/**
 * @author sdyang
 * @date 2019/10/21 17:08
 **/
@Component("cHECK_IS_NUMBERIC")
public class CHECK_IS_NUMBERIC extends AbstractCheckRule {

    @Override
    public BaseResult check(String cxt, String value) {

        boolean isNumber = false;

        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        isNumber = pattern.matcher(value).matches();

        if (!isNumber) {
            return BaseResult.getFailure("%s不是数字", value);
        }

        return BaseResult.getSuccess();
    }
}
